
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>Introduction to atomman: Running LAMMPS and the Log class &#8212; atomman 1.4.0 documentation</title>
    <link rel="stylesheet" href="../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
    <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true, "ignoreClass": "document", "processClass": "math|output_area"}})</script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Introduction to atomman: Basic support and analysis tools" href="3._Basic_support_and_analysis_tools.html" />
    <link rel="prev" title="Introduction to atomman: LAMMPS Potentials" href="2.1._Potential_class.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="3._Basic_support_and_analysis_tools.html" title="Introduction to atomman: Basic support and analysis tools"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="2.1._Potential_class.html" title="Introduction to atomman: LAMMPS Potentials"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">atomman 1.4.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Tutorials</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  
<style>
/* CSS for nbsphinx extension */

/* remove conflicting styling from Sphinx themes */
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt *,
div.nbinput.container div.input_area pre,
div.nboutput.container div.output_area pre,
div.nbinput.container div.input_area .highlight,
div.nboutput.container div.output_area .highlight {
    border: none;
    padding: 0;
    margin: 0;
    box-shadow: none;
}

div.nbinput.container > div[class*=highlight],
div.nboutput.container > div[class*=highlight] {
    margin: 0;
}

div.nbinput.container div.prompt *,
div.nboutput.container div.prompt * {
    background: none;
}

div.nboutput.container div.output_area .highlight,
div.nboutput.container div.output_area pre {
    background: unset;
}

div.nboutput.container div.output_area div.highlight {
    color: unset;  /* override Pygments text color */
}

/* avoid gaps between output lines */
div.nboutput.container div[class*=highlight] pre {
    line-height: normal;
}

/* input/output containers */
div.nbinput.container,
div.nboutput.container {
    display: -webkit-flex;
    display: flex;
    align-items: flex-start;
    margin: 0;
    width: 100%;
}
@media (max-width: 540px) {
    div.nbinput.container,
    div.nboutput.container {
        flex-direction: column;
    }
}

/* input container */
div.nbinput.container {
    padding-top: 5px;
}

/* last container */
div.nblast.container {
    padding-bottom: 5px;
}

/* input prompt */
div.nbinput.container div.prompt pre {
    color: #307FC1;
}

/* output prompt */
div.nboutput.container div.prompt pre {
    color: #BF5B3D;
}

/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
    width: 4.5ex;
    padding-top: 5px;
    position: relative;
    user-select: none;
}

div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
    position: absolute;
    right: 0;
    margin-right: 0.3ex;
}

@media (max-width: 540px) {
    div.nbinput.container div.prompt,
    div.nboutput.container div.prompt {
        width: unset;
        text-align: left;
        padding: 0.4em;
    }
    div.nboutput.container div.prompt.empty {
        padding: 0;
    }

    div.nbinput.container div.prompt > div,
    div.nboutput.container div.prompt > div {
        position: unset;
    }
}

/* disable scrollbars on prompts */
div.nbinput.container div.prompt pre,
div.nboutput.container div.prompt pre {
    overflow: hidden;
}

/* input/output area */
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
    -webkit-flex: 1;
    flex: 1;
    overflow: auto;
}
@media (max-width: 540px) {
    div.nbinput.container div.input_area,
    div.nboutput.container div.output_area {
        width: 100%;
    }
}

/* input area */
div.nbinput.container div.input_area {
    border: 1px solid #e0e0e0;
    border-radius: 2px;
    /*background: #f5f5f5;*/
}

/* override MathJax center alignment in output cells */
div.nboutput.container div[class*=MathJax] {
    text-align: left !important;
}

/* override sphinx.ext.imgmath center alignment in output cells */
div.nboutput.container div.math p {
    text-align: left;
}

/* standard error */
div.nboutput.container div.output_area.stderr {
    background: #fdd;
}

/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }

.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }

.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }


div.nbinput.container div.input_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight].math,
div.nboutput.container div.output_area.rendered_html,
div.nboutput.container div.output_area > div.output_javascript,
div.nboutput.container div.output_area:not(.rendered_html) > img{
    padding: 5px;
    margin: 0;
}

/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */
div.nbinput.container div.input_area > div[class^='highlight'],
div.nboutput.container div.output_area > div[class^='highlight']{
    overflow-y: hidden;
}

/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt a.copybtn {
    display: none;
}

/* Some additional styling taken form the Jupyter notebook CSS */
div.rendered_html table {
  border: none;
  border-collapse: collapse;
  border-spacing: 0;
  color: black;
  font-size: 12px;
  table-layout: fixed;
}
div.rendered_html thead {
  border-bottom: 1px solid black;
  vertical-align: bottom;
}
div.rendered_html tr,
div.rendered_html th,
div.rendered_html td {
  text-align: right;
  vertical-align: middle;
  padding: 0.5em 0.5em;
  line-height: normal;
  white-space: normal;
  max-width: none;
  border: none;
}
div.rendered_html th {
  font-weight: bold;
}
div.rendered_html tbody tr:nth-child(odd) {
  background: #f5f5f5;
}
div.rendered_html tbody tr:hover {
  background: rgba(66, 165, 245, 0.2);
}
</style>
<div class="section" id="Introduction-to-atomman:-Running-LAMMPS-and-the-Log-class">
<h1>Introduction to atomman: Running LAMMPS and the Log class<a class="headerlink" href="#Introduction-to-atomman:-Running-LAMMPS-and-the-Log-class" title="Permalink to this headline">¶</a></h1>
<p><strong>Lucas M. Hale</strong>, <a class="reference external" href="mailto:lucas&#46;hale&#37;&#52;&#48;nist&#46;gov?Subject=ipr-demo">lucas<span>&#46;</span>hale<span>&#64;</span>nist<span>&#46;</span>gov</a>, <em>Materials Science and Engineering Division, NIST</em>.</p>
<p><a class="reference external" href="http://www.nist.gov/public_affairs/disclaimer.cfm">Disclaimers</a></p>
<div class="section" id="1.-Introduction">
<h2>1. Introduction<a class="headerlink" href="#1.-Introduction" title="Permalink to this headline">¶</a></h2>
<p>This Notebook outlines the options of the atomman.lammps.Log class and the atomman.lammps.run() function.</p>
<p><strong>Library Imports</strong></p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Standard libraries</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">glob</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">datetime</span>

<span class="c1"># http://matplotlib.org/</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="o">%</span><span class="k">matplotlib</span> inline

<span class="c1"># https://github.com/usnistgov/atomman</span>
<span class="kn">import</span> <span class="nn">atomman</span> <span class="k">as</span> <span class="nn">am</span>
<span class="kn">import</span> <span class="nn">atomman.lammps</span> <span class="k">as</span> <span class="nn">lmp</span>
<span class="kn">import</span> <span class="nn">atomman.unitconvert</span> <span class="k">as</span> <span class="nn">uc</span>

<span class="c1"># Show atomman version</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;atomman version =&#39;</span><span class="p">,</span> <span class="n">am</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span>

<span class="c1"># Show date of Notebook execution</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Notebook executed on&#39;</span><span class="p">,</span> <span class="n">datetime</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">())</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
atomman version = 1.4.0
Notebook executed on 2021-08-05
</pre></div></div>
</div>
</div>
<div class="section" id="2.-Running-LAMMPS">
<h2>2. Running LAMMPS<a class="headerlink" href="#2.-Running-LAMMPS" title="Permalink to this headline">¶</a></h2>
<p><em>Updated version 1.4.0:</em> Parameters updated to provide more running options and remove obsolete Log class-based parameters.</p>
<p>The LAMMPS simulation can be ran from within Python using the run() function. This runs LAMMPS as a subprocess, meaning that it can use any installed LAMMPS and MPI executables.</p>
<p>Parameters</p>
<ul class="simple">
<li><p><strong>lammps_command</strong> <em>(str</em>) The LAMMPS inline run command (sans -in script_name).</p></li>
<li><p><strong>script_name</strong> <em>(str, optional</em>) Path of the LAMMPS input script file to use. Either script_name or script must be given.</p></li>
<li><p><strong>script</strong> <em>(str, optional</em>) The LAMMPS input script command lines to use. Either script_name or script must be given.</p></li>
<li><p><strong>mpi_command</strong> <em>(str or None, optional</em>) The MPI inline command to run LAMMPS in parallel. Default value is None (run serially).</p></li>
<li><p><strong>restart_script_name</strong> <em>(str or None, optional</em>) Path to an alternate LAMMPS input script file to use for restart runs. If given, the restart script will be used if the specified logfile already exists. Requires logfile to not be None.</p></li>
<li><p><strong>restart_script</strong> (<em>str, optional</em>) Alternate LAMMPS script command lines to use for restart runs. If given, the restart script will be used if the specified logfile already exists. Requires logfile to not be None.</p></li>
<li><p><strong>logfile</strong> <em>(str or None, optional</em>) Specifies the path to the logfile to write to. Default value is ‘log.lammps’. If set to None, then no logfile will be created.</p></li>
<li><p><strong>screen</strong> <em>(bool, optional</em>) If True (default), then the resulting Log object is built from the LAMMPS screen output. If False, then LAMMPS outputs no screen info and the Log object will be built by reading logfile.</p></li>
<li><p><strong>suffix</strong> <em>(str, optional</em>) Allows for the LAMMPS suffix option to be specified to use any of the accelerated versions of pair styles if available.</p></li>
</ul>
<p>Returns</p>
<ul class="simple">
<li><p>(<em>atomman.lammps.Log</em>) An object representation of the log.lammps file.</p></li>
</ul>
<p>Create a simple demonstration LAMMPS input script</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">script</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">#Simple demonstration LAMMPS script</span>

<span class="s2">units metal</span>
<span class="s2">atom_style atomic</span>
<span class="s2">boundary p p p</span>

<span class="s2">lattice fcc 3.52 origin 0.100000 0.100000 0.100000</span>

<span class="s2">region box block 0 15 0 15 0 15</span>
<span class="s2">create_box 1 box</span>
<span class="s2">create_atoms 1 box</span>

<span class="s2">mass 1 58.71</span>

<span class="s2">pair_style lj/cut 6</span>
<span class="s2">pair_coeff 1 1 0.5408 2.272</span>

<span class="s2">velocity all create 100 2987532</span>

<span class="s2">thermo 100</span>
<span class="s2">thermo_style custom step pe temp press lx ly lz</span>

<span class="s2">restart 10000 *.restart</span>

<span class="s2">timestep 0.01</span>

<span class="s2">fix 1 all npt temp 100 100 1.0 aniso 0.0 0.0 10.0</span>
<span class="s2">run 10000</span>

<span class="s2">&quot;&quot;&quot;</span>
</pre></div>
</div>
</div>
<p>Run in serial</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Define lammps command to use (unique to your computer!)</span>
<span class="n">lammps_command</span> <span class="o">=</span> <span class="s1">&#39;lmp_mpi&#39;</span>

<span class="c1"># Run and measure execution time</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">lmp</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">lammps_command</span><span class="p">,</span> <span class="n">script</span><span class="o">=</span><span class="n">script</span><span class="p">)</span>
<span class="n">end</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">run_time</span> <span class="o">=</span> <span class="n">end</span><span class="o">-</span><span class="n">start</span>

<span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;Serial simulation took </span><span class="si">{run_time}</span><span class="s2"> seconds.&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
Serial simulation took 98.3661994934082 seconds.
</pre></div></div>
</div>
<p>Run in parallel on 4 processors</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[4]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Define lammps command to use (unique to your computer!)</span>
<span class="n">lammps_command</span> <span class="o">=</span> <span class="s1">&#39;lmp_mpi&#39;</span>

<span class="c1"># Define mpi command to use (unique to your computer!)</span>
<span class="n">mpi_command</span> <span class="o">=</span> <span class="s1">&#39;C:/Program Files/MPICH2/bin/mpiexec.exe -localonly 4&#39;</span>

<span class="c1"># Run and measure execution time</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">lmp</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">lammps_command</span><span class="p">,</span> <span class="n">script</span><span class="o">=</span><span class="n">script</span><span class="p">,</span> <span class="n">mpi_command</span><span class="o">=</span><span class="n">mpi_command</span><span class="p">)</span>
<span class="n">end</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">run_time</span> <span class="o">=</span> <span class="n">end</span><span class="o">-</span><span class="n">start</span>

<span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;Parallel simulation took </span><span class="si">{run_time}</span><span class="s2"> seconds.&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
Parallel simulation took 47.57556772232056 seconds.
</pre></div></div>
</div>
</div>
<div class="section" id="3.-Accessing-results-with-Log-class">
<h2>3. Accessing results with Log class<a class="headerlink" href="#3.-Accessing-results-with-Log-class" title="Permalink to this headline">¶</a></h2>
<p><em>Updated version 1.3.7</em>: now captures performance output. A Simulation class is added to better represent each run/simulation. The flatten method is updated to return a new Simulation rather than overwriting the current data. New ‘all’ style added to flatten that will merge all runs without filtering out duplicate timesteps.</p>
<p>Information from the log.lammps file(s) is automatically parsed by the run() function and returned as an atomman.lammps.Log object. Currently, the Log class stores the following information:</p>
<ul class="simple">
<li><p><strong>lammps_version</strong> (<em>str</em>) The LAMMPS version used.</p></li>
<li><p><strong>lammps_date</strong> (<em>datetime.date</em>) The date associated with the LAMMPS version.</p></li>
<li><p><strong>simulations</strong> (<em>list</em>) information for each simulation (run, minimize …) that was executed.</p></li>
</ul>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;results.lammps_version -&gt;&quot;</span><span class="p">,</span> <span class="n">results</span><span class="o">.</span><span class="n">lammps_version</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;results.lammps_date -&gt;&quot;</span><span class="p">,</span> <span class="n">results</span><span class="o">.</span><span class="n">lammps_date</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
results.lammps_version -&gt; 3 Mar 2020
results.lammps_date -&gt; 2020-03-03
</pre></div></div>
</div>
<p>Each simulation captures the associated thermo data lines and the computational performance data in separate pandas.DataFrames.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">results</span><span class="o">.</span><span class="n">simulations</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">thermo</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
</pre></div>
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
Index([&#39;Step&#39;, &#39;PotEng&#39;, &#39;Temp&#39;, &#39;Press&#39;, &#39;Lx&#39;, &#39;Ly&#39;, &#39;Lz&#39;], dtype=&#39;object&#39;)
</pre></div></div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[7]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">results</span><span class="o">.</span><span class="n">simulations</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">performance</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[7]:
</pre></div>
</div>
<div class="output_area rendered_html docutils container">
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>min time</th>
      <th>avg time</th>
      <th>max time</th>
      <th>%varavg</th>
      <th>%total</th>
    </tr>
    <tr>
      <th>Section</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Pair</td>
      <td>24.363000</td>
      <td>24.627000</td>
      <td>24.884000</td>
      <td>5.0</td>
      <td>88.57</td>
    </tr>
    <tr>
      <td>Neigh</td>
      <td>0.005595</td>
      <td>0.005656</td>
      <td>0.005722</td>
      <td>0.1</td>
      <td>0.02</td>
    </tr>
    <tr>
      <td>Comm</td>
      <td>1.087600</td>
      <td>1.347400</td>
      <td>1.616000</td>
      <td>21.7</td>
      <td>4.85</td>
    </tr>
    <tr>
      <td>Output</td>
      <td>0.010593</td>
      <td>0.010796</td>
      <td>0.011395</td>
      <td>0.3</td>
      <td>0.04</td>
    </tr>
    <tr>
      <td>Modify</td>
      <td>1.530100</td>
      <td>1.533900</td>
      <td>1.536700</td>
      <td>0.2</td>
      <td>5.52</td>
    </tr>
    <tr>
      <td>Other</td>
      <td>0.000000</td>
      <td>0.281500</td>
      <td>0.000000</td>
      <td>0.0</td>
      <td>1.01</td>
    </tr>
  </tbody>
</table>
</div></div>
</div>
<p>This makes it very easy to plot the simulation thermo data</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[8]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="k">for</span> <span class="n">simulation</span> <span class="ow">in</span> <span class="n">results</span><span class="o">.</span><span class="n">simulations</span><span class="p">:</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">simulation</span><span class="o">.</span><span class="n">thermo</span><span class="o">.</span><span class="n">Step</span><span class="p">,</span> <span class="n">simulation</span><span class="o">.</span><span class="n">thermo</span><span class="o">.</span><span class="n">PotEng</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/tutorial_2.2._Running_LAMMPS_and_the_Log_class_17_0.png" src="../_images/tutorial_2.2._Running_LAMMPS_and_the_Log_class_17_0.png" />
</div>
</div>
</div>
<div class="section" id="4.-Restarting-and-flattening">
<h2>4. Restarting and flattening<a class="headerlink" href="#4.-Restarting-and-flattening" title="Permalink to this headline">¶</a></h2>
<p>There is also some built-in functionality for conveniently handling simulations containing multiple runs and/or multiple sequential simulation executions of the same overall run (i.e. restarts).</p>
<div class="section" id="4.1.-Running-with-restart-script-included">
<h3>4.1. Running with restart script included<a class="headerlink" href="#4.1.-Running-with-restart-script-included" title="Permalink to this headline">¶</a></h3>
<p>Create a new demonstration LAMMPS input script that restarts the previous simulation and runs for an additional 10000 steps.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[10]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">restart_script</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">#Simple demonstration LAMMPS restart script</span>

<span class="s2">read_restart *.restart</span>

<span class="s2">mass 1 58.71</span>

<span class="s2">pair_style lj/cut 6</span>
<span class="s2">pair_coeff 1 1 0.5408 2.272</span>

<span class="s2">thermo 100</span>
<span class="s2">thermo_style custom step pe temp press lx ly lz</span>

<span class="s2">restart 10000 *.restart</span>

<span class="s2">fix 1 all npt temp 100 100 1.0 aniso 0.0 0.0 10.0</span>
<span class="s2">run 10000</span>

<span class="s2">&quot;&quot;&quot;</span>
</pre></div>
</div>
</div>
<p>Now, if we call run() with either restart_script_name or restart_script set, a number of cool things happen:</p>
<ul class="simple">
<li><p>If logfile (default log.lammps) does not exist in the working directory then the regular script is passed to LAMMPS./</p></li>
<li><p>If logfile does exist then it is moved from NAME.EXT to NAME-<a href="#id1"><span class="problematic" id="id2">*</span></a>.EXT, where * is the smallest integer not already there, and the restart script is passed to LAMMPS.</p></li>
<li><p>Upon completion, the data in NAME.EXT logfile and all NAME-<a href="#id3"><span class="problematic" id="id4">*</span></a>.EXT logfiles are automatically read in by the Log object.</p></li>
</ul>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[11]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
    <span class="n">results</span> <span class="o">=</span> <span class="n">lmp</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">lammps_command</span><span class="p">,</span> <span class="n">script</span><span class="o">=</span><span class="n">script</span><span class="p">,</span> <span class="n">mpi_command</span><span class="o">=</span><span class="n">mpi_command</span><span class="p">,</span> <span class="n">restart_script</span><span class="o">=</span><span class="n">restart_script</span><span class="p">)</span>
</pre></div>
</div>
</div>
<p>Show all log files in the run directory</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[12]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="k">for</span> <span class="n">logfile</span> <span class="ow">in</span> <span class="n">glob</span><span class="o">.</span><span class="n">iglob</span><span class="p">(</span><span class="s1">&#39;*.lammps&#39;</span><span class="p">):</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">logfile</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
log-1.lammps
log-2.lammps
log-3.lammps
log.lammps
</pre></div></div>
</div>
<p>Show that results now has two simulations, one for steps 0 to 10000 and one for steps 10000 to 20000 (the restart)</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[13]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="k">for</span> <span class="n">simulation</span> <span class="ow">in</span> <span class="n">results</span><span class="o">.</span><span class="n">simulations</span><span class="p">:</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">simulation</span><span class="o">.</span><span class="n">thermo</span><span class="o">.</span><span class="n">Step</span><span class="p">,</span> <span class="n">simulation</span><span class="o">.</span><span class="n">thermo</span><span class="o">.</span><span class="n">PotEng</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/tutorial_2.2._Running_LAMMPS_and_the_Log_class_26_0.png" src="../_images/tutorial_2.2._Running_LAMMPS_and_the_Log_class_26_0.png" />
</div>
</div>
</div>
<div class="section" id="4.2.-Flattening-data-from-multiple-simulations-together">
<h3>4.2. Flattening data from multiple simulations together<a class="headerlink" href="#4.2.-Flattening-data-from-multiple-simulations-together" title="Permalink to this headline">¶</a></h3>
<p><em>Changed version 1.3.7</em> flatten now returns a new Simulation rather than overwriting the current content.</p>
<p>The Log.flatten() method creates a new Simulation object that combines the thermo data from all of the simulations. flatten takes a single parameter that specifies how thermo lines with duplicate timesteps are treated:</p>
<ul class="simple">
<li><p>‘last’ (default) will use values for each timestep from the last runs where they appear. This is useful for MD restart runs where thermo data from eariler runs may be incomplete if externally stopped.</p></li>
<li><p>‘first’ will use values for each timestep from the first runs where they appear. This is useful for quasistatic simulations where minimizations are performed under different conditions and only the final relaxed state of each condition is important.</p></li>
<li><p>‘all’ will use all thermo lines from all simulations including ones with the same timesteps. This is useful for “run 0” simulations of different conditions, or if the timestep is reset.</p></li>
</ul>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[14]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">allsims</span> <span class="o">=</span> <span class="n">results</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="s1">&#39;last&#39;</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">allsims</span><span class="o">.</span><span class="n">thermo</span><span class="o">.</span><span class="n">Step</span><span class="p">,</span> <span class="n">allsims</span><span class="o">.</span><span class="n">thermo</span><span class="o">.</span><span class="n">PotEng</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<img alt="../_images/tutorial_2.2._Running_LAMMPS_and_the_Log_class_28_0.png" src="../_images/tutorial_2.2._Running_LAMMPS_and_the_Log_class_28_0.png" />
</div>
</div>
<p>Note that only thermo data is included in the merged simulation and not the performance data.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[15]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="nb">repr</span><span class="p">(</span><span class="n">allsims</span><span class="o">.</span><span class="n">performance</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[15]:
</pre></div>
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
&#39;None&#39;
</pre></div></div>
</div>
</div>
</div>
<div class="section" id="5.-Error-messages">
<h2>5. Error messages<a class="headerlink" href="#5.-Error-messages" title="Permalink to this headline">¶</a></h2>
<p><em>LAMMPSError added and error handling improved version 1.3.2</em></p>
<p>To assist in running LAMMPS simulations, a LAMMPSError error type is defined which does its best to extract the error message that LAMMPS issues as a Python error.</p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[16]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="c1"># Create a demo script with an error: missing a value in the fix npt line</span>
<span class="n">bad_script</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">#Simple demonstration LAMMPS script</span>

<span class="s2">units metal</span>
<span class="s2">atom_style atomic</span>
<span class="s2">boundary p p p</span>

<span class="s2">lattice fcc 3.52 origin 0.100000 0.100000 0.100000</span>

<span class="s2">region box block 0 15 0 15 0 15</span>
<span class="s2">create_box 1 box</span>
<span class="s2">create_atoms 1 box</span>

<span class="s2">mass 1 58.71</span>

<span class="s2">pair_style lj/cut 6</span>
<span class="s2">pair_coeff 1 1 0.5408 2.272</span>

<span class="s2">velocity all create 100 2987532</span>

<span class="s2">thermo 100</span>
<span class="s2">thermo_style custom step pe temp press lx ly lz</span>

<span class="s2">restart 10000 *.restart</span>

<span class="s2">timestep 0.01</span>

<span class="s2">fix 1 all npt temp 100 100 1.0 aniso 0.0 0.0</span>
<span class="s2">run 10000</span>

<span class="s2">&quot;&quot;&quot;</span>
</pre></div>
</div>
</div>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[17]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="k">try</span><span class="p">:</span>
    <span class="n">results</span> <span class="o">=</span> <span class="n">lmp</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">lammps_command</span><span class="p">,</span> <span class="n">script</span><span class="o">=</span><span class="n">bad_script</span><span class="p">,</span> <span class="n">mpi_command</span><span class="o">=</span><span class="n">mpi_command</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
    <span class="nb">print</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">ex</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="s1">&#39;raised with message&#39;</span><span class="p">)</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">ex</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
LammpsError raised with message
Illegal fix nvt/npt/nph command (../fix_nh.cpp:153)
Last command: fix 1 all npt temp 100 100 1.0 aniso 0.0 0.0

</pre></div></div>
</div>
<p><strong>File Cleanup</strong></p>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[18]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre>
<span></span><span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s1">&#39;log.lammps&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">restart</span> <span class="ow">in</span> <span class="n">glob</span><span class="o">.</span><span class="n">iglob</span><span class="p">(</span><span class="s1">&#39;*.restart&#39;</span><span class="p">):</span>
    <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">restart</span><span class="p">)</span>
<span class="k">for</span> <span class="n">restart</span> <span class="ow">in</span> <span class="n">glob</span><span class="o">.</span><span class="n">iglob</span><span class="p">(</span><span class="s1">&#39;log-*.lammps&#39;</span><span class="p">):</span>
    <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">restart</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Introduction to atomman: Running LAMMPS and the Log class</a><ul>
<li><a class="reference internal" href="#1.-Introduction">1. Introduction</a></li>
<li><a class="reference internal" href="#2.-Running-LAMMPS">2. Running LAMMPS</a></li>
<li><a class="reference internal" href="#3.-Accessing-results-with-Log-class">3. Accessing results with Log class</a></li>
<li><a class="reference internal" href="#4.-Restarting-and-flattening">4. Restarting and flattening</a><ul>
<li><a class="reference internal" href="#4.1.-Running-with-restart-script-included">4.1. Running with restart script included</a></li>
<li><a class="reference internal" href="#4.2.-Flattening-data-from-multiple-simulations-together">4.2. Flattening data from multiple simulations together</a></li>
</ul>
</li>
<li><a class="reference internal" href="#5.-Error-messages">5. Error messages</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="2.1._Potential_class.html"
                        title="previous chapter">Introduction to atomman: LAMMPS Potentials</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="3._Basic_support_and_analysis_tools.html"
                        title="next chapter">Introduction to atomman: Basic support and analysis tools</a></p>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="3._Basic_support_and_analysis_tools.html" title="Introduction to atomman: Basic support and analysis tools"
             >next</a> |</li>
        <li class="right" >
          <a href="2.1._Potential_class.html" title="Introduction to atomman: LAMMPS Potentials"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">atomman 1.4.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >Tutorials</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.2.0.
    </div>
  </body>
</html>